package com.youlin.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Objects;

@NoArgsConstructor
@Data
@Accessors(chain=true)
public class BaseResDto<S extends Status, M extends String> {

    @ApiModelProperty(value="业务响应状态码：1000-请求成功，1001-请求失败，1002-请求参数错误，" +
            "1005-权限不足，1006-未登录, 1027-请重新登录(密码已重置或账号已在其它终端登录)", position = 1)
    private Integer status;

    @ApiModelProperty(value="业务响应信息", position = 2)
    private String message;

    public BaseResDto(S status) {
        this.status = status.getValue();
        this.message = status.getMessage();
    }

    public BaseResDto(S status, M message) {
        this.status = status.getValue();
        this.message = message;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BaseResDto)) return false;
        BaseResDto<?, ?> that = (BaseResDto<?, ?>) o;
        return getStatus().equals(that.getStatus());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getStatus());
    }

}
